package com.hxd.otc.module.convenience.activity;

import android.content.Intent;
import android.net.Uri;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseRecyclerActivity;
import com.hxd.otc.module.convenience.adapter.AppStoreAdapter;
import com.hxd.otc.module.convenience.bean.AppStoreBean;
import com.hxd.otc.module.convenience.contract.AppStoreContract;
import com.hxd.otc.module.convenience.presenter.AppStorePresenter;

/**
 * Created by lzy on 2019/1/3 0003.
 * description ${应用市场}
 */
public class AppStoreActivity extends BaseRecyclerActivity<AppStorePresenter, AppStoreAdapter, AppStoreBean> implements AppStoreContract.IView, AppStoreAdapter.OnDownloadListener {


    @Override
    protected AppStoreAdapter createAdapter() {
        return new AppStoreAdapter(this);
    }

    @Override
    protected AppStorePresenter createPresenter() {
        return new AppStorePresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_app_store;
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        mAdapter.setOnDownloadListener(this);
    }

    @Override
    public void onDownload(AppStoreBean appStoreBean) {
        onSkipDownLoadLink(appStoreBean.getDownload());
        mPresenter.countDownloadNums(appStoreBean.getId());
    }

    private void onSkipDownLoadLink(String url) {
        Intent intent = new Intent();
        intent.setData(Uri.parse(url));//Url 就是你要打开的网址
        intent.setAction(Intent.ACTION_VIEW);
        this.startActivity(intent); //启动浏览器
    }
}
